@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <link rel="stylesheet" href="/lib/layer/theme/default/layer.css"/>
    <script type="text/javascript" src="/lib/layer/layer.js"></script>
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/wechat/news">微信图文管理</a></li>
                <li class="active">图文列表</li>
            </ul>
        </div>
        <div class="main-content">
            <div class="btn-toolbar list-toolbar">
                <form class="form-inline" action="" method="get">
                    <a href="/wechat/addnew"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" ><i class="fa fa-plus"></i> 新增</button></a>
                    <div class="form-group">
                        <input type="text" class="form-control" name="title" placeholder="课程标题" value="{{$title}}">
                    </div>
                    <button type="submit" class="btn btn-default">筛选</button>
                </form>
            </div>
            <div class="row">
                <div class="col-sm-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading no-collapse">课程列表</div>
                        <table class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>图文标题</th>
                                <th>图文简介</th>
                                <th>封面图</th>
                                <th>跳转地址</th>
                                <th>排序值</th>
                                <th>最后操作人</th>
                                <th>编辑时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($courseClass as $class)
                                <tr id="news_{{$class->id}}">
                                    <td>{{$class->id}}</td>
                                    <td>{{$class->title}}</td>
                                    <td>
                                    {{$class->description}}
                                    </td>
                                    <td>
                                        <img class="pimg" height="80" src="{{env('IMG_URL')}}{{$class->picurl}}" />
                                    </td>
                                    <td>{{$class->url}}</td>
                                    <td>{{$class->orderby}}</td>
                                    <td>{{$class->users->name}}</td>
                                    <td>{{$class->updated_at}}</td>
                                    <td class="text-justify" style="width:189px;">
                                        <a class="btn btn-success btn-xs" href="/wechat/editnew/{{$class->id}}">编辑</a>
                                        <button class="btn btn-danger btn-xs" data-id="{{$class->id}}" onclick="courseDelete(this)">删除</button>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            {{$courseClass->appends(['title'=>$title])->render()}}
        </div>
    </div>
    <script type="text/javascript">
        function courseDelete(obj){
            var id     = $(obj).attr('data-id');
            var _token = '{{csrf_token()}}';
            var data   = {id:id,_token:_token};
            layer.confirm('确定删除吗？', {
                btn: ['是', '否'],
            }, function(index){
                $.ajax({
                    url:'/wechat/delnew',
                    data:data,
                    type:'POST',
                    dataType: 'json',
                    success:function(res){
                        layer.alert(res.message);
                        if(res.code == 0){
                            $("#news_"+id).remove();
                        }

                    }
                });
                layer.close(index);
                return true;
            }, function(index){
                layer.close(index);
            });

        }
    </script>
@endsection